package com.yndsoft.jc.supplier.utils;

import android.content.Context;

public class DensityUtil {

    /**
     * 把dp单位的值换算成像素单位的值
     */
    public static int dp2px(Context context, int dp) {
        float density = context.getResources().getDisplayMetrics().density;
        int px = (int) (dp * density + 0.5f);
        return px;
    }

    /**
     * 把像素单位的值换算成dp单位的值
     */
    public static int px2dp(Context context, int px) {
        float density = context.getResources().getDisplayMetrics().density;
        int dp = (int) (px / density + 0.5f);
        return dp;
    }

}
